package com.geekaca.d4.work1;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class GetDuration {
    public static void main(String[] args) {
        getDuration("2020-10-01 12:34:56", "2023-10-02 12:45:09");
        getDuration("2019-10-01 12:34:56", "2023-12-27 12:45:09");
    }

    public static void getDuration(String startTime, String endTime) {
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        LocalDateTime parseStart = LocalDateTime.parse(startTime, dtf);
        LocalDateTime parseEnd = LocalDateTime.parse(endTime, dtf);

        Duration duration = Duration.between(parseStart, parseEnd);
        System.out.println("相差 " + duration.getSeconds() + "秒");


    }
}
